<?php
//include the functions.php
require "include/functions.php";
//check_session();

/*
	Generates the quiry data for current stock level
	Created by		 : Lee
	Created On		 : 29.August.2011
	Last Modification: created document
	Modified On		 : 29.August.2011
	Modified By		 : Lee
*/

// Define Data Variables
$userName = "";
$email = "";

// Requestings inputs from the form to php variables

if(!filter_has_var(INPUT_POST, "user_name")){}
else
	{
		$userName = $_REQUEST["user_name"];
	}
if(!filter_has_var(INPUT_POST, "email")){}
else
	{
		$email = $_REQUEST["email"];
	}
?>

<html>
<head>
<title>Home Electronics - User Listing</title>
<link rel="stylesheet" href="include/styles.css" type="text/css">
<script src="include/functions.js"></script>
<script>window.onload=function(){
	altRows('alternatecolor');
}</script>
</head>
<body>
<div id="container" align="center">
  	
	<div id="body" align="center">
		<div>
		<h1>User Listing</h1> 
			<fieldset style="width:94%; text-align:center">
            <legend>Search Criteria</legend>
            <form name="form1" action="user_listing.php" method="post">
            <table style="margin-right:28%">
            	<tr>
                    <td>Name</td><td><input name='user_name' value='<?=$userName?>'/></td>
					<td>Email</td><td><input name='email' value='<?=$email?>'/></td>
					<td><input type="submit" name="Search"></td>
                </tr>
            </table>
            </form>
            </fieldset>
			<br/>
			<p style="font-size:14px"><b>Type:</b> 0 Meaning Customer, 1 Meaning Administrator</p>
		    <?php
			$table = ("user u");
			$table_rows= array ("u.user_id","u.user_name","u.email","u.user_type","u.postal_address","u.shipping_address");
			$condition = ("(user_name like '$userName%' or user_name='') and (email like '$email%' or email='')");
		
			echo("<table class='altrowstable' id='alternatecolor'><tr><th width='5%'>ID</th><th>Name</th><th>Email</th><th width='5%'>Type</th><th>Post Address</th><th>Shipping Address</th></tr>");
			$result = query_table("home_electronics","home","home_e",$table,$table_rows,$condition, false, false);
			
			// Replaces No data = 0 
			$what = array("No data");
			$for   = array("0");
			$result = str_replace($what, $for, $result);
		

			echo($result."<table></a>");
			?>

		
		</div>  
	</div> <!--body div -->
   	</div>
</body>
</html>